import pandas as pd
import os
from datetime import datetime

def write_to_excel(data,region):
    columns = ["业务号", "业务名", "取号数", "未呼数", "已呼叫", "办理中", "群众平均办理时长(分钟)", "窗口平均办理时长(分钟)", "平均等待时长(分钟)"]
    df = pd.DataFrame(data, columns=columns)
    
    # 创建日期格式目录
    today = datetime.now().strftime("%Y%m%d")
    dir_name = f"{today}业务办件效能导出"
    if not os.path.exists(dir_name):
        os.makedirs(dir_name)
    
    # 保存文件到新建目录
    df.to_excel(os.path.join(dir_name, f'{region}.xlsx'), index=False)
